package com.ishitong.platform.utils.encrypt;

import java.security.MessageDigest;

/**
 * 功能描述：将字符串以md5格式加密
 * @author liufeng
 *
 */
public class Encrypt
{

	public Encrypt()
	{
	}

	public static String md5encode(String inStr)
	{
		MessageDigest md5;
		try
		{
			md5 = MessageDigest.getInstance("md5");
		} catch (Exception e)
		{
			return "";
		}
		char charArray[] = inStr.toCharArray();
		byte byteArray[] = new byte[charArray.length];
		for (int i = 0; i < charArray.length; i++)
			byteArray[i] = (byte) charArray[i];

		byte md5Bytes[] = md5.digest(byteArray);
		StringBuffer hexValue = new StringBuffer();
		byte arr[] = md5Bytes;
		int len = arr.length;
		for (int i = 0; i < len; i++)
		{
			byte md5Byte = arr[i];
			int val = md5Byte & 0xff;
			if (val < 16)
				hexValue.append("0");
			hexValue.append(Integer.toHexString(val));
		}

		return hexValue.toString();
	}
}